﻿@using Newtouch.Infrastructure;
@{
    ViewBag.Title = "Index";
    Layout = "~/Views/Shared/_Index.cshtml";
    //是否可结算 病区中的患者
    var isSettContainsBQZ = SysConfigReader.Bool("HOSP_Sett_Contains_BQZ", false).Value;
    var brzybzType = ((int)EnumZYBZ.Djz).ToString();
    //if (isSettContainsBQZ)
    //{
    brzybzType += "," + ((int)EnumZYBZ.Bqz).ToString();
    //}
    //有与CPOE互通接口
    //var interfaceWithCPOE = SysConfigReader.Bool("HOSP_INTERFACE_WITH_CPOE", false).Value;

    //是否和医保交易
    var openYbSett = SysConfigReader.Bool("Inpatient_Sett_OpenYbSett");
    //是否和新农合交易
    var openXnhSett = SysConfigReader.Bool("Inpatient_Sett_OpenXnhSett");
    //医保所属地，区分系统将执行何处医保逻辑
    var medicalInsurance = SysConfigReader.String("Inpatient_MedicalInsurance");

    var opr = Newtouch.Common.Operator.OperatorProvider.GetCurrent();
}

<div class="rows" style="margin-bottom: 1%;">
    <div class="panel panel-default" style="margin-bottom:0;">
        <div class="panel-heading navb-bg">
            住院患者信息
        </div>
        <table class="form" style="width:96%;">
            <tbody>
                <tr>
                    <th class="formTitle">住院号：</th>
                    <td class="formValue">
                        <input class="form-control" type="text" id="zyh" value="" />
                    </td>
                    <td class="formValue">
                        <input type="button" class="btn btn-default btn-md btn-default-color" title="选择住院患者" id="zy_btnsyy" value="查询" onclick="GetPatSerarchView();">
                    </td>
                    <th class="formTitle">姓名：</th>
                    <td class="formValue">
                        <label id="xm"></label>
                    </td>
                    <th class="formTitle">性别：</th>
                    <td class="formValue">
                        <label id="xb"></label>
                    </td>
                    <th class="formTitle">年龄：</th>
                    <td class="formValue">
                        <label id="nlshow"></label>
                    </td>
                    <th class="formTitle">出院诊断：</th>
                    <td class="formValue">
                        <label id="cyzd"></label>
                    </td>
                </tr>
            </tbody>
            <tbody>
                <tr>

                    <th class="formTitle">费用性质：</th>
                    <td class="formValue" colspan="2">
                        <label id="zyxz"></label>
                    </td>
                    <th class="formTitle">住院天数：</th>
                    <td class="formValue">
                        <label id="zyts"></label>
                    </td>
                    <th class="formTitle">出生日期：</th>
                    <td class="formValue">
                        <label id="csny"></label>
                    </td>
                    <th class="formTitle">入院日期：</th>
                    <td class="formValue">
                        <label id="ryrq"></label>
                    </td>
                    <th class="formTitle">出院日期：</th>
                    <td class="formValue">
                        <label id="cyrq"></label>
                    </td>
                </tr>
            </tbody>
        </table>
    </div>
</div>
<div class="gridPanel" style="margin-top:1%">
    <table id="gridList"></table>
    <div id="gridPager"></div>
</div>

@Html.Partial("_BottomButtonsView", new Newtouch.HIS.Web.Core.Models.BottomButtonViewModel()
{
    ShowKeyList = new int[] { 4, 8 },
    F8Text = "结算"
})

<script>
    var openYbSett = '@openYbSett' === 'True'; //开关配置：医保患者是否使用医保交易流程
    var openXnhSett = '@openXnhSett' === 'True'; //开关配置：新农合患者是否使用新农合医保交易流程
    var isYbjyjz; //当前是否走医保交易的就诊
    var isXnhjyjz;
    var medicalInsurance = '@medicalInsurance';

    $(function () {
        gridListData();
    });

    //病人查询(住院)
    function GetPatSerarchView() {
        $.modalOpen({
            id: "patSearch",
            title: "患者查询",
            url: "/PatientManage/AccountManage/PatSearchView?brzybzType=" + '@(brzybzType)' + "&t=" + Math.random() + "&zyh=" + $("#zyh").val(),
            width: "700px",
            height: "600px",
            callBack: function (iframeId) {
                top.frames[iframeId].PatDbGrid(); //在弹出窗口事件
                //调用查询卡号和住院号
            }//窗口点确定的回调函数
        });
    }

    //选择的病人 callback
    function getPatInfoAjax(selePatInfo) {
        //清一下
        newtouch_globalevent_f4();
        //
        patModel = null;
        jszje = 0.00;
        if (selePatInfo && selePatInfo.zyh) {
            $('#zyh').val(selePatInfo.zyh);
            ajaxLoadDataResult(selePatInfo.zyh);
        }
        else {
            $('#zyh').val('');
        }
    }

    //
    var patModel = null;
    //
    var jszje = 0.00;

    //根据zyh 病人基本信息、计费信息
    function ajaxLoadDataResult(zyh) {
        $.najax({
            type: "POST",
            url: "/HospitalizationManage/DischargeSettle/GetInpatientSettleStatusDetail",
            data: { zyh: zyh, jslx: 'mnjs' },
            dataType: "json",
            success: function (ajaxresp) {
                //住院病人信息
                patModel = ajaxresp.data.InpatientSettPatInfo;

                isYbjyjz = openYbSett && patModel.brxz == '1' && patModel.CardType == "@((int)Newtouch.Infrastructure.EnumCardType.YBJYK)";
                isXnhjyjz = openXnhSett && patModel.brxz == '8' && patModel.CardType == "@((int)Newtouch.Infrastructure.EnumCardType.XNHJYK)";

                $('#xm').html(patModel.xm);
                $('#xb').html($.getGender(patModel.xb));
                $("#nlshow").html(getAgeFromBirthTime({ begin: patModel.csny }).text);
                //$('#ryzd').html(patModel.ryzdmc);
                $('#cyzd').html(patModel.cyzd);
                $('#zyxz').html(patModel.brxzmc);
                $('#zyts').html(patModel.zyts);
                $('#csny').html(patModel.csny ? patModel.csny.substring(0, 10) : '');
                $('#ryrq').html(patModel.ryrq ? patModel.ryrq.substring(0, 10) : '');
                $('#cyrq').html(patModel.cyrq ? patModel.cyrq.substring(0, 10) : '');

                if (ajaxresp.data.GroupFeeVOList && ajaxresp.data.GroupFeeVOList.length) {
                    loadJfmxByZyh(ajaxresp.data.GroupFeeVOList);
                }
                else {
                    $.modalAlert("尚未产生费用，不能结算", 'warning');
                    return false;
                }
            },
            errorCallback: function (data) {
                newtouch_globalevent_f4();
                $('#zyh').trigger('focus');
            }
        });
    }

    //总金额合计
    function loadJfmxByZyh(data) {
        //$('#gridList').jqGrid("clearGridData");   //早F4过了
        $("#gridList").newtouchLocalDataGrid(null, data);
        //总金额
        var zje = 0;
        $.each(data, function () {
            if (this.je) {
                zje += this.je;
            }
        });
        if (zje) {
            jszje = zje.toFixed(2);;
            $("#yeCon").text(zje.toFixed(2));
        }
    }

    function newtouch_event_f4() {
        $('#xm').html('');
        $('#xb').html('');
        $('#nlshow').html('');
        //$('#ryzd').html('');
        $('#cyzd').html('');
        $('#zyxz').html('');
        $('#zyts').html('');
        $('#csny').html('');
        $('#ryrq').html('');
        $('#cyrq').html('');
        patModel = null;
        jszje = 0.00;
        $('#yeCon').text('0.00');
        $('#gridList').jqGrid("clearGridData");
    }

    //绑定grid
    function gridListData() {
        var captionCon = "计费明细&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;总金额：<label style='color:red;'>￥</label></span>&nbsp;<span id='yeCon' class='moneybg' style='font-size:large;'>" + "0.00" + "</span>元";
        var $gridList = $("#gridList");
        $gridList.newtouchLocalDataGrid({
            height: $(window).height() - 225,
            unwritten: false,
            caption: captionCon,
            colModel: [
                { label: 'dlCode', name: 'dlCode', hidden: true },
                { label: '费用类别', name: 'dlmc', width: 100, align: 'left' },
                {
                    label: '金额', name: 'je', width: 500, align: 'left', formatter: "number"
                    , formatoptions: { decimalPlaces: 2, defaultValue: '0.00' }
                },
            ],
            onSelectRow: function (rowIndex, s) {
                getItemsbySfdl(rowIndex);
            }
        });
    }

    //保存结算
    function newtouch_event_f8() {
        //if (isXnhjyjz) {
        //    $.modalAlert("新农合患者不能模拟结算！", 'warning');
        //    return;
        //}
        if (!patModel || !patModel.zyh) {
            $.modalAlert("住院号为空", 'warning');
            return;
        }
        var data = $("#gridList").jqGrid('getRowData_AllLine');
        if (!(data && data.length)) {
            $.modalAlert("尚未产生费用，不能结算.", 'warning')
            return;
        }
        if (!patModel.ryrq) {
            $.modalAlert("入院日期为空", 'warning');
            return;
        }

        hisSubmit();
    }

    //
    function hisSubmit() {
        //
        var zyh = patModel.zyh;
        var ryrq = $.getDate({ date: patModel.ryrq });
        var zje = jszje;
        //
        var openUrl = "/HospitalizationManage/DischargeSettle/SimulateForm?zyh=" + zyh;
        openUrl += "&ryrq=" + (!!ryrq ? ryrq : '');
        openUrl += "&hisfyze=" + zje;
        openUrl += "&isYbjyjz=" + isYbjyjz;
        openUrl += "&isXnhjyjz=" + isXnhjyjz; 
        openUrl += "&medicalInsurance=" + medicalInsurance;
        $.modalOpen({
            id: "FormSimulateSettConfirm",
            title: "模拟结算-结果查看",
            url: openUrl,
            width: "600px",
            height: "400px",
            btn: ['确定'],
            callBack: function (iframeId) {
                $.modalClose(iframeId);
                return;
            }
        });
    }
    function getItemsbySfdl(id) {
        var rowData = $("#gridList").jqGrid('getRowData', id);
        if (!!rowData) {
            var sfdl = rowData.dlCode;
            $.modalOpen({
                id: "Sfdlfeedetail",
                title: "明细项目查询",
                url: "/HospitalizationManage/DischargeSettle/SimulateFeeItems?dlCode=" + sfdl + "&zyh=" + $("#zyh").val(),
                width: "800px",
                height: "600px",
                btn: null,
                callBack: function (iframeId) {
                }
            });
        }
    }
</script>
